package com.wxapp.pay.service.controller.client;

import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.common.core.filter.except.ThrowMyException;
import com.wxapp.pay.api.pojo.pojo.vm.pay.PPaySelectVm;
import com.wxapp.pay.api.pojo.pojo.vm.pay.PPayStatusVm;
import com.wxapp.pay.api.pojo.pojo.vm.payConfig.PConfigVm;
import com.wxapp.pay.api.pojo.pojo.vo.pay.QAliPayCallBackVo;
import com.wxapp.pay.api.pojo.pojo.vo.pay.QPayVo;
import com.wxapp.pay.api.pojo.pojo.vo.pay.QWechatCallBackVo;
import com.wxapp.pay.service.service.PayService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lgl
 */
@RestController
@Tag(name = "支付")
@RequestMapping("/client/pay")
@RequiredArgsConstructor
public class PayClientController extends IBaseController {
    private final PayService payService;

    @PostMapping("toPay")
    @Operation(summary = "支付")
    public ResultVm<String> pay(@Schema(hidden = true) @User UserVo userVo, @RequestBody QPayVo vo) throws ThrowMyException {
        return payService.pay(userVo, vo);
    }

    @PostMapping("getStatus/{orderCode}")
    @Operation(summary = "获取支付状态")
    public ResultVm<PPayStatusVm> getStatus(@PathVariable String orderCode) throws ThrowMyException {
        return payService.getStatus(orderCode);
    }

    @GetMapping("/getPaySelect")
    @Operation(summary = "获取支付下拉框")
    public ResultVm<List<PPaySelectVm>> getPaySelect() {
        return payService.getPaySelect();
    }


    @PostMapping("/weChatCallBack")
    @Operation(summary = "微信支付回调")
    @Hidden
    public ResultVm<List<PConfigVm>> wechatCallBack(@RequestBody QWechatCallBackVo vo) throws ThrowMyException {
        return payService.wechatCallBack(vo);
    }

    @PostMapping("/aliPayNotify")
    @Operation(summary = "支付宝支付回调")
    @Hidden
    public String aliPayCallBack(QAliPayCallBackVo vo) throws ThrowMyException {
        return payService.aliPayCallBack(vo).getData();
    }
}
